package com.lmq.wxshare.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lmq.wxshare.entity.Orders;
import com.lmq.wxshare.mapper.OrderMapper;
import com.lmq.wxshare.service.OrderService;
import org.springframework.stereotype.Service;

@Service
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Orders> implements OrderService {

    @Override
    public Orders saveOrupdte(int userid, int produceid, Integer redpacket) {
        //根据用户id查找，如果存在的话返回原来的，不做更改
        Orders order = null;
        int count = baseMapper.selectCount(new QueryWrapper<Orders>().eq("user_id", userid));
        boolean flag = count>0?true:false;
        if(!flag){
            order = new Orders(produceid, userid, redpacket);
            baseMapper.insert(order);
        }else{
            order = baseMapper.selectOne(new QueryWrapper<Orders>().eq("user_id", userid));
        }
        return order;
    }
}
